package com.gcl.usercenter.exception;

import com.gcl.usercenter.common.BaseResponse;
import com.gcl.usercenter.common.ErrorCode;
import com.gcl.usercenter.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler<T> {

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<T> runtimeExceptionHandler(Exception e) {
        log.error("runtimeException" + e.getMessage(), e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<T> businessExceptionHandler(BusinessException be) {
        log.error("businessException" + be.getMessage(), be);
        return ResultUtils.error(be.getCode(),be.getMessage(),be.getDescription());
    }
}
